<template>
   <div class="login-box">
      <el-form>
         <el-form-item label="用户名">
            <el-input v-model="user.username"></el-input>
         </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="user.password"></el-input>
        </el-form-item>
        <el-form-item >
          <el-button type="success" @click="btnLoginClick">登录</el-button>
        </el-form-item>
      </el-form>

   </div>


</template>

<script lang="ts" setup>

      import router from '@/router'
      import axios from "axios";

      import {reactive} from "vue";

      /**
       * 响应式数据
       * */
      const user = reactive({
        username:'',
        password:''
      })

      let btnLoginClick=()=>{

        axios({
          url:'http://localhost:8080/user/login',
          method:'get',
          headers:{
            token:localStorage.getItem("token")
          },
          params:user
        }).then((res:any)=>{
             if(res.data.success){
               localStorage.setItem("token",res.data.token);
                router.push("/list")
             }

        })

      // /**
      //  *  学生Id 1
      //  *  调准页面
      //  * */
      //
      //
      // /**
      //  *  以 key-value
      //  *  把数据保存在本地文件中
      //  * */
      // sessionStorage.setItem("stuid","1");
      //
      // router.push({
      //    path:'/list'
      // });
   }


</script>

<style scoped>

</style>